package com.parachutes.aspinterfacecore.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.util.StringUtil;
import com.parachutes.aspinterfaceapi.domain.BusInterface;
import com.parachutes.aspinterfaceapi.domain.dto.BusInterfaceDTO;
import com.parachutes.aspinterfaceapi.service.BusInterfaceService;
import com.parachutes.aspinterfacecore.mapper.BusInterfaceMapper;

import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author machi
* @description 针对表【bus_interface(接口表)】的数据库操作Service实现
* @createDate 2025-01-23 10:07:00
*/
@Service
public class BusInterfaceServiceImpl extends ServiceImpl<BusInterfaceMapper, BusInterface>
    implements BusInterfaceService {

    /**
     * private int page;
     *     private int pageSize;
     *     private int status; // 1: active, 2: inactive
     *     private String name;
     *     private String desc;
     *     private String method;   // GET, POST, PUT, DELETE
     *     private String billingRules;
     *     private int priceMin;
     *     private int priceMax;
     *     private int avgResponseTimeMin;
     *     private int avgResponseTimeMax;
     * @param busInterfaceDTO
     * @return
     */
    @Override
    public List<BusInterface> getList(BusInterfaceDTO busInterfaceDTO) {
        LambdaQueryWrapper<BusInterface> queryWrapper = Wrappers.lambdaQuery(BusInterface.class)
                .like(StringUtil.isNotEmpty(busInterfaceDTO.getName()), BusInterface::getName, busInterfaceDTO.getName())
                .like(StringUtil.isNotEmpty(busInterfaceDTO.getDesc()), BusInterface::getDesc, busInterfaceDTO.getDesc())
                .eq(StringUtil.isNotEmpty(busInterfaceDTO.getMethod()), BusInterface::getMethod, busInterfaceDTO.getMethod())
                .like(StringUtil.isNotEmpty(busInterfaceDTO.getBillingRules()), BusInterface::getBillingRules, busInterfaceDTO.getBillingRules())
                .ge(busInterfaceDTO.getPriceMin() > 0, BusInterface::getPrice, busInterfaceDTO.getPriceMin())
                .le(busInterfaceDTO.getPriceMax() > 0, BusInterface::getPrice, busInterfaceDTO.getPriceMax())
                .ge(busInterfaceDTO.getAvgResponseTimeMin() > 0, BusInterface::getAvgResponseTime, busInterfaceDTO.getAvgResponseTimeMin())
                .le(busInterfaceDTO.getAvgResponseTimeMax() > 0, BusInterface::getAvgResponseTime, busInterfaceDTO.getAvgResponseTimeMax())
                .in(StringUtil.isNotEmpty(busInterfaceDTO.getStatus()), BusInterface::getStatus, busInterfaceDTO.getStatus());
        return this.list(queryWrapper);
    }
}




